var app = getApp();

Page({
    data: {
      userInfo: {},
    },
    onLoad: function () {
      wx.setNavigationBarTitle({
        title: '我的资料'
      });
      var _this = this;
      //调用应用实例的方法获取全局数据
      app.getUserInfo(function (userInfo) {
        //更新数据
        _this.setData({
          userInfo: userInfo
        });
      });
    },
    onShow: function () {
    },

  formSubmit: function (e) {
      var id = e.target.dataset.id;
      var submitObject = e.detail.value || {};
      var _this = this;
        wx.showToast({
          title: '正在提交数据...',
          icon: 'loading',
          duration: 10000
        });
        app.getUserInfo(function (userInfo) {
          submitObject.openId = userInfo.openId
          console.log(submitObject);
          wx.request({
            url: app.globalData.domain + 'api/update_user_info',
            data: submitObject,
            method: 'post',
            success: function (res) {
              app.globalData.userInfo = res.data.userInfo
              _this.setData({
                users: res.data.userInfo,
              });
              wx.showToast({
                title: '保存成功',
                icon: 'success',
                duration: 2000,
                complete: function () {
                  wx.switchTab({
                    url: '/pages/my/my'
                  });
                }
              });
            },
            fail: function () { },
            complete: function () { }
          });
        });


      

    }







});